<template>
	<view class="changeAccount">
		<view class="accountArea">
			<view class="accountIpt">
				<input type="number" v-model="account" placeholder="请输入手机号">
			</view>
			<view class="msgAreaw">
				<input type="number" v-model="code" maxlength="6" placeholder="请输入验证码">
				<view class="getCode" @click="getCodeEvent()">{{getCodeText}}</view>
			</view>
			<view class="msgAreaw">
				<input  type="password" v-model="password" placeholder="请输入密码">
			</view>
			<view class="msgAreaw">
				<input  type="password" v-model="new_password" placeholder="确认密码">
			</view>
		</view>
		<view class="submit" @click="submitEvent()">确定</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				account: '',
				password: '',
				new_password: '',
				code: '',
				getCodeText: '获取验证码',
			}
		},
		methods: {
			getCodeEvent(){
				var that = this;
				uni.hideKeyboard()
				if(this.getCodeisWaiting == true){
					return
				}
				
				that.getCodeText = "发送中..."
				that.getCodeisWaiting = true;
				that.getCodeBtnColor = "rgba(255,255,255,0.5)"
				this.$show();
				this.$http.post('index/mobile_code',{
					mobile:this.account
				}).then((res)=>{
					this.$hide()
					that.getCodeText = "发送中..."
					that.getCodeisWaiting = true;
					that.getCodeBtnColor = "rgba(255,255,255,0.5)"
					//示例用定时器模拟请求效果
					setTimeout(() => {
						uni.showToast({
							title: '验证码已发送',
							icon: "none"
						});
						that.setTimer();
					})
				})
			},
			setTimer() {
				let holdTime = 60;
				this.getCodeText = "重新获取(60)"
				this.Timer = setInterval(() => {
					if (holdTime <= 0) {
						this.getCodeisWaiting = false;
						this.getCodeBtnColor = "#ffffff";
						this.getCodeText = "获取验证码"
						clearInterval(this.Timer);
						return;
					}
					this.getCodeText = "重新获取(" + holdTime + ")"
					holdTime--;
				}, 1000)
			},
			submitEvent(){
				if(!this.account){
					return this.$Toast('请输入手机号');
				}
				if(!this.code){
					return this.$Toast('请输入短信验证码');
				}
				if(!this.password){
					return this.$Toast('请输入密码');
				}
				if(!this.new_password){
					return this.$Toast('请确认密码');
				}
				if(this.password != this.new_password){
					return this.$Toast('两次密码不一样');
				}
				let params = {
					mobile: this.account,
					code: this.code,
					password: this.password
				}
				uni.request({
					url: 'https://oa.yuxiang123.cn/api/index/forget_password',
					header: {
						"content-type": "application/x-www-form-urlencoded"
					},
					method: 'POST',
					data:params,
					success: (res) => {
						this.$Toast(res.data.msg);
						if(res.data.code == 1){
							uni.setStorageSync('token', res.data.data.token);
							uni.setStorageSync('userInfo', res.data.data.user);
							setTimeout(() => {
								uni.switchTab({
									url:'/pages/shop/shopClass'
								})
							}, 1000)
						}
					}
				})
			},
		}
	}
</script>
<style>
	page{
		width: 100%;
		height: 100%;
		background: url('https://oa.yuxiang123.cn/assets/task/shop/pass_bann.png') no-repeat;
	}
</style>
<style lang="scss" scoped>
	.radio{
	display: flex;
	align-items: center;
	justify-content: center;
	margin-top: 40upx;
	.box{
		width:40upx;
		height:40upx;
	}
	.text{
		font-size: 26upx;
		color: #999999;
		margin-left: 10upx;
		text{
			color: #07C160;
			text-decoration:underline;
		}
	}
}
	.changeAccount{
		position: relative;
	}
	
	.accountArea{
		padding-top: 200rpx;
		width: 100%;
	}
	
	.accountImg{
		position: absolute;
		width: 100%;
		height: 100%;
	}
	
	.accountIpt,.msgAreaw{
		padding: 10upx 0;
		border-bottom: 2px solid #f5f5f5;
		margin: 0 40upx;
	}
	.msgAreaw{
		display: flex;
		align-items: center;
		margin-top: 50rpx;
		input{
			flex: 1;
		}
		.getCode{
			font-size: 28upx;
		}
	}
	.submit{
		background-color: #3662EC;
		color: #fff;
		width: 90%;
		margin:60rpx 5%;
		text-align: center;
		font-size: 30upx;
		line-height: 80upx;
		border-radius: 50upx;
		font-weight: bold;
		
	}

	.outAccount{
		background-color:#aaa;
		color:#fff;
		width: 90%;
		margin: auto;
		text-align: center;
		font-size: 30upx;
		line-height: 80upx;
		border-radius: 50upx;
		font-weight: bold;
		position: fixed;
		left: 0;
		right: 0;
		bottom: 100rpx;
	}

</style>
